3.5 spthin降低采样偏差

library(spocc)
library(spThin)
library(dismo)
library(rgeos)
library(ENMeval)
library(dplyr)
getwd()

## 方法1:
##使用shinny界面:
run_wallace()


##  方法2,SPthin;
#### 使用脚本的来清洗数据:
## 数据导入与清理:
source(system.file('shiny/funcs', 'functions.R', package = 'wallace'))
## 
userOccs.path <- "./yanmo/.csv"
userOccs.csv <- read.csv(userOccs.path, header = TRUE)
# remove rows with duplicate coordinates
occs.dups <- duplicated(userOccs.csv[c('longitude', 'latitude')])
occs <- userOccs.csv[!occs.dups,]
# remove NAs
occs <- occs[complete.cases(occs$longitude, occs$latitude), ]

output <- spThin::thin(occs, 'latitude', 'longitude', 'name', 
                       thin.par = 5, reps = 100, 
                       locs.thinned.list.return = TRUE, 
                       write.files = FALSE, verbose = FALSE)

### 基于最优迭代构建最优输出:
maxThin <- which(sapply(output, nrow) == max(sapply(output, nrow)))
# if there's more than one max, pick the first one
maxThin <- output[[ifelse(length(maxThin) > 1, maxThin[1], maxThin)]]  
# subset occs to match only thinned occs
occs <- occs[as.numeric(rownames(maxThin)),]  

write.csv(occs,"./sa.csv")

3.5.2 使用半方差来降低采样密度

## 解决空间自相关:
library(gstat)
c.variog <- variogram(Chuckwalla ~1, chuck.sp.trn, xlab= "Distance (m)", ylab="Semivariance")
plot(c.variog) #check training data for SA (it there)

c.variog2 <- variogram(Chuckwalla ~1, chuck.sp.tst, xlab= "Distance (m)", ylab="Semivariance")
plot(c.variog2) #check testing data for SA (it there)

### Zooming in a bit to focus on local effects
c.variog3 <- variogram(Chuckwalla ~1, chuck.sp.trn,cutoff = 50000)
c.variog3.f <- fit.variogram(c.variog3, vgm(psill = 0.1, "Sph", range = 25000, nugget = 0))
plot(c.variog3, model = c.variog3.f)

library(sp)
data(meuse)
head(meuse)
# no trend:
coordinates(meuse) = ~x+y
variogram(log(zinc)~1, meuse)
# residual variogram w.r.t. a linear trend:
variogram(log(zinc)~x+y, meuse)
# directional variogram:
aa <- variogram(log(zinc)~x+y, meuse, alpha=c(0,45,90,135))
bb <- variogram(log(zinc)~1, meuse, width=90, cutoff=1300)
plot(bb)
variogram(Chuckwalla ~1, k.chuck.trn, cutoff = 50000, xlab= "Distance (m)", ylab="Semivariance")

results matching ""

    No results matching ""